package br.com.vertigo.sgci.session;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import br.com.vertigo.sgci.entity.Itemrdv;
import br.com.vertigo.sgci.entity.Projetotipoitem;
import br.com.vertigo.sgci.entity.Rdv;

@SuppressWarnings("serial")
@Name("itemrdvHome")
public class ItemrdvHome extends EntityHome<Itemrdv> {

	@In(create = true)
	ProjetotipoitemHome projetotipoitemHome;
	@In(create = true)
	RdvHome rdvHome;

	public void setItemrdvIdItemrdv(Long id) {
		setId(id);
	}

	public Long getItemrdvIdItemrdv() {
		return (Long) getId();
	}

	@Override
	protected Itemrdv createInstance() {
		Itemrdv itemrdv = new Itemrdv();
		return itemrdv;
	}

	public void wire() {
		getInstance();
		Projetotipoitem projetotipoitem = projetotipoitemHome
				.getDefinedInstance();
		if (projetotipoitem != null) {
			getInstance().setProjetotipoitem(projetotipoitem);
		}
		Rdv rdv = rdvHome.getDefinedInstance();
		if (rdv != null) {
			getInstance().setRdv(rdv);
		}
	}

	public boolean isWired() {
		if (getInstance().getProjetotipoitem() == null)
			return false;
		if (getInstance().getRdv() == null)
			return false;
		return true;
	}

	public Itemrdv getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public String persist(){
		setCreatedMessage("");
		return super.persist();
	}
	
	public String update(){
		setUpdatedMessage("");
		return super.update();
	}
	
	public String remove(){
		setDeletedMessage("");
		return super.remove();
	}
}
